﻿
Imports DynamicVCD.Core.Entities
Imports DynamicVCD.Core
Imports System.Threading.Tasks

Partial Public Class MainPage
    Inherits PhoneApplicationPage

    ' Constructor
    Public Sub New()
        InitializeComponent()

        SupportedOrientations = SupportedPageOrientation.Portrait Or SupportedPageOrientation.Landscape

        ' Sample code to localize the ApplicationBar
        'BuildLocalizedApplicationBar()

        CreateCommands()
    End Sub

    Private Sub CreateCommands()
        OpenDocumentCommand = New Command() With {.Name = "OpenDocument", .Feedback = "Open document", .Example = "Open a document"}
        OpenDocumentCommand.ListenForList.Add("open [a] document")
        OpenDocumentCommand.ListenForList.Add("show [a] document")

        DeleteDocumentCommand = New Command() With {.Name = "DeleteDocument", .Feedback = "Delete document", .Example = "Delete a document"}
        DeleteDocumentCommand.ListenForList.Add("delete [a] document")
        DeleteDocumentCommand.ListenForList.Add("remove [a] document")

        SendDocumentCommand = New Command() With {.Name = "SendDocument", .Feedback = "Send document", .Example = "send a document"}
        SendDocumentCommand.ListenForList.Add("sand [a] document")
    End Sub

    Dim OpenDocumentCommand As Command
    Dim DeleteDocumentCommand As Command
    Dim SendDocumentCommand As Command

    Private Async Sub Button_Click_3(sender As Object, e As RoutedEventArgs)
        Dim vcd = New VoiceCommandDefinition

        Dim cs = New CommandSet
        cs.Name = "Demo"
        cs.Culture = System.Threading.Thread.CurrentThread.CurrentCulture.Name
        cs.CommandPrefix = "Demo"
        cs.Example = "Sample"
        vcd.AddCommandSet(cs)

        If OpenDocument.IsChecked Then
            cs.AddCommand(OpenDocumentCommand)
        End If
        If DeleteDocument.IsChecked Then
            cs.AddCommand(DeleteDocumentCommand)
        End If
        If SendDocument.IsChecked Then
            cs.AddCommand(SendDocumentCommand)
        End If

        Try
            Await VoiceCommandService.InstallVoiceCommandDefinitionAsync(vcd)
            MessageBox.Show("VCD registrato correttamente")
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try

    End Sub


    Public Async Function InstallVCD() As task
        Dim vcd = New VoiceCommandDefinition
        ' Define command set
        Dim cs = New CommandSet
        cs.Name = "MyAppCommandSet"
        cs.Culture = "en-US"
        cs.CommandPrefix = "MyApp"
        cs.Example = "Sample"
        vcd.AddCommandSet(cs)
        ' Define single Command 
        Dim c = New Command() With {.Name = "OpenDocument",
                                    .Feedback = "I'm opening a document...",
                                    .Example = "Open a document"}
        c.ListenForList.Add("open [a] document")
        c.ListenForList.Add("show [a] document")
        cs.AddCommand(c)
        ' Try to install the VCD
        Try
            Await VoiceCommandService.InstallVoiceCommandDefinitionAsync(vcd)
            MessageBox.Show("VCD installed correctly")
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Function

End Class